let request = require('operation.js')

module.exports.getNotice = getNotice

function getNotice(noticeSid,kcalssSid = '0') {
  let path = '/notices/' + noticeSid
  if ('0' != kcalssSid) {
    path = path + '?klassSid=' + kcalssSid
  }

  return new Promise((resolve, reject) => {
    request.getRequest(path, {}, true)
      .then(res => {
        wx.stopPullDownRefresh()

        var data = res.data;
        if (request.SUCCESSED == data.status) {          
          resolve(data.object)
        } else if (-4 == data.status){
          reject(data)
        }else if (data.msg.indexOf('不存在') > 0) {
            reject(data)
        }else {
          wx.showToast({
            title: data.msg,
            iocn: 'none'
          })
        }
      })
      .catch(e => {
        console.log(e)
      })
  })
}